package com.motorwaymanage.actions;

import java.util.List;

import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import com.motorwaymanage.beans.ApplyInfo;
import com.motorwaymanage.beans.JsonObject;
import com.motorwaymanage.beans.MaintainerInfo;
import com.motorwaymanage.biz.IApplyInfoBiz;
import com.motorwaymanage.impl.ApplyInfoBizImpl;
import com.opensymphony.xwork2.ActionSupport;

public class ApplyInfoAction extends ActionSupport{

	private static final long serialVersionUID = 1L;
	
	//private List<ApplyInfo> list;
	private IApplyInfoBiz applyInfoBiz=new ApplyInfoBizImpl();
	private JsonObject json;
	private HttpSession session;
	private String laddr;
	private int aid;
	{
		session=ServletActionContext.getRequest().getSession();
	}
	
	public String OneApplyInfo(){
		IApplyInfoBiz applyInfoBiz=new ApplyInfoBizImpl();
		MaintainerInfo mi=(MaintainerInfo) session.getAttribute("staffInfo");
		List<ApplyInfo> list=applyInfoBiz.selectApplyInfo(mi.getMid());
		if(list!=null){
			json=new JsonObject();
			json.setObj("rows");
			json.setRows(list);
			return SUCCESS;
		}else{
			return null;
		}
	}
	
	public String Add_applyInfo(){
		MaintainerInfo mi=(MaintainerInfo) session.getAttribute("staffInfo");
		json=new JsonObject();
		int result=applyInfoBiz.addApplyInfo(new ApplyInfo(0,mi.getMid(),laddr,0,0));
		json.setObj(result);
		return SUCCESS;
	}
	
	public String updateAstatus(){
		json=new JsonObject();
		int result=applyInfoBiz.modifyAstInfo(aid, laddr);
		json.setObj(result);
		return SUCCESS;
	}
	
	public String AllApplyInfo(){
		List<ApplyInfo> list=applyInfoBiz.selectApplyInfo(0);
		if(list!=null){
			json=new JsonObject();
			json.setRows(list);
			return SUCCESS;
		}
		return null;
	}
	
	public String updateAok(){
		json=new JsonObject();
		int result=applyInfoBiz.modifyAokInfo(aid, laddr);
		json.setObj(result);
		return SUCCESS;
	}
	
	public String delApplyInfo(){
		json=new JsonObject();
		int result=applyInfoBiz.delApplyInfo(aid);
		json.setObj(result);
		return SUCCESS;
	}
	
	public JsonObject getJson() {
		return json;
	}

	public void setLaddr(String laddr) {
		this.laddr = laddr;
	}

	public void setAid(int aid) {
		this.aid = aid;
	}
}
